package com.rp.system.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rp.common.utils.RpUtil;
import com.rp.log.annotation.RpLog;
import com.rp.system.dao.RoleMenuDao;
import com.rp.system.po.RoleMenu;

@Service
@Transactional
public class RoleMenuService {

	@Autowired
	private RoleMenuDao roleMenuDao;
	
	
	@RpLog(desc="更新角色菜单")
	public void updateRoleMenu(String roleId, String menuId, String menuItemIds){
		
		List<RoleMenu> dbRms = roleMenuDao.find("from RoleMenu where roleId = ? and menuId = ?", roleId, menuId);
		if(dbRms.size() > 0){
			RoleMenu dbRm = dbRms.get(0);
			dbRm.setMenuItemIds(menuItemIds);
			roleMenuDao.update(dbRm);
		}else{
			RoleMenu rm = new RoleMenu();
			rm.setRoleId(roleId);
			rm.setMenuId(menuId);
			rm.setMenuItemIds(menuItemIds);
			rm.setCreateDate(RpUtil.getCurrentDatetime());
			roleMenuDao.save(rm);
		}
		
	}
	
	
	
	
	
	public RoleMenuDao getRoleMenuDao() {
		return roleMenuDao;
	}
	
}
